package com.byq.mm.smartlib.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;


import com.byq.mm.abstractx.device.Device;
import com.byq.mm.smartlib.R;
import com.byq.mm.smartlib.tools.SimpleDeviceAdapter;

public class SubDevicesActivity extends AbstractSmartActivity {

	Device device;
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    String globalId = this.getIntent().getExtras().getString("globalId");
    device = application.getAndroidSmartEngine().getCoreEngine().getClientDeviceManager().getDeviceClient(globalId).getDevice();
    
    
    setContentView(R.layout.subdevices);
   
    
    TextView name = (TextView)this.findViewById(R.id.deviceName);
    TextView id = (TextView)this.findViewById(R.id.deviceId);
    name.setText(device.getName());
    id.setText(device.getTransportId());
    
    ListView subdevices = (ListView)this.findViewById(R.id.subdevices);
    subdevices.setAdapter(new SimpleDeviceAdapter(this,device, true));
    subdevices.setOnItemClickListener(new OnItemClickListener(){

		@Override
		public void onItemClick(AdapterView<?> av, View v, int arg2,
				long arg3) {
			SimpleDeviceAdapter.ViewHolder holder = (SimpleDeviceAdapter.ViewHolder)v.getTag();
			Intent intent = new Intent();
            intent.setPackage(SubDevicesActivity.this.getPackageName());
			intent.setClass(SubDevicesActivity.this, DeviceActivity.class);
			
			intent.putExtra("globalId", holder.device.getGlobalId());
			startActivity(intent);
			
		}
  
    
    });
  }
}
